<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>cors解决跨域</title>
</head>
<body>
<h3>cors解决跨域</h3>
<button id="btn">点我获取数据</button>
<script type="text/javascript">
    const btn = document.getElementById('btn')
    btn.onclick = () => {
        const xhr = new XMLHttpRequest()
        xhr.onreadystatechange = () => {
            if (xhr.readyState === 4) {
                if (xhr.status >= 200 && xhr.status < 300) {
                    console.log(xhr.response)
                    console.log(xhr.getAllResponseHeaders())
                }
            }
        }
        xhr.open('GET', 'http://localhost:8080/test_cors')
        xhr.send()
    }
</script>
</body>
</html>
